home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / assocc1 / example.frm < prev    next >
Text File  |  1995-09-06  |  4KB  |  170 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Assoc Example"
  5.    ClientHeight    =   2685
  6.    ClientLeft      =   4035
  7.    ClientTop       =   3000
  8.    ClientWidth     =   2010
  9.    Height          =   3090
  10.    Left            =   3975
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2685
  15.    ScaleWidth      =   2010
  16.    Top             =   2655
  17.    Width           =   2130
  18.    Begin CommandButton btnExit 
  19.       Caption         =   "Exit"
  20.       Height          =   252
  21.       Left            =   1320
  22.       TabIndex        =   2
  23.       Top             =   2280
  24.       Width           =   612
  25.    End
  26.    Begin CommandButton btnAssoc 
  27.       Caption         =   "Assoc"
  28.       Height          =   372
  29.       Left            =   120
  30.       TabIndex        =   1
  31.       Top             =   2160
  32.       Width           =   852
  33.    End
  34.    Begin CommandButton btnArray 
  35.       Caption         =   "Array"
  36.       Height          =   372
  37.       Left            =   120
  38.       TabIndex        =   0
  39.       Top             =   1680
  40.       Width           =   852
  41.    End
  42.    Begin PictureBox Addrs 
  43.       Height          =   336
  44.       Left            =   1560
  45.       ScaleHeight     =   300
  46.       ScaleWidth      =   300
  47.       TabIndex        =   5
  48.       Top             =   1680
  49.       Width           =   336
  50.    End
  51.    Begin Label lblExplain2 
  52.       AutoSize        =   -1  'True
  53.       Caption         =   "The output appears in the Debug window."
  54.       Height          =   384
  55.       Left            =   120
  56.       TabIndex        =   4
  57.       Top             =   960
  58.       Width           =   1812
  59.       WordWrap        =   -1  'True
  60.    End
  61.    Begin Label lblExplain1 
  62.       AutoSize        =   -1  'True
  63.       Caption         =   "Click on Array or Assoc to load names and addresses."
  64.       Height          =   576
  65.       Left            =   120
  66.       TabIndex        =   3
  67.       Top             =   120
  68.       Width           =   1812
  69.       WordWrap        =   -1  'True
  70.    End
  71. End
  72.  
  73. Option Explicit
  74.  
  75. Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
  76.  
  77. Sub Addrs_Enumerate (Key As String, Value As String)
  78.     Debug.Print Key, Value
  79. End Sub
  80.  
  81. Sub btnArray_Click ()
  82.     Call TryArray
  83. End Sub
  84.  
  85. Sub btnAssoc_Click ()
  86.     Call TryAssoc
  87. End Sub
  88.  
  89. Sub btnExit_Click ()
  90.     Unload frmMain
  91. End Sub
  92.  
  93. Sub TryArray ()
  94.  
  95.     Dim DataFile As String
  96.     Dim Surname As String, Address As String
  97.     Dim I As Integer, N As Integer
  98.  
  99.     ' Set the full path for the data file
  100.     If Right$(App.Path, 1) = "\" Then
  101.     DataFile = App.Path & "ADDR.DAT"
  102.     Else
  103.     DataFile = App.Path & "\" & "ADDR.DAT"
  104.     End If
  105.  
  106.     ' Read in the names and addresses
  107.     Open DataFile For Input As #1
  108.     For I = 1 To 100
  109.     If EOF(1) Then N = I - 1: Exit For
  110.     Input #1, Surname
  111.     If EOF(1) Then N = I - 1: Exit For
  112.     ' .. in case there was a blank line
  113.     Input #1, Address
  114.     Surnames(I) = Surname
  115.     Addresses(I) = Address
  116.     Next I
  117.     Close #1
  118.  
  119.     ' Dump the arrays to the Debug window
  120.     Debug.Print
  121.     Debug.Print "Array ..."
  122.     For I = 1 To N
  123.     Debug.Print Surnames(I), Addresses(I)
  124.     Next I
  125.  
  126. End Sub
  127.  
  128. Sub TryAssoc ()
  129.  
  130.     Dim DataFile As String
  131.     Dim Surname As String, Address As String
  132.     Const ASSOC_ENUMERATE = 0
  133.  
  134.     ' Set the full path for the data file
  135.     If Right$(App.Path, 1) = "\" Then
  136.     DataFile = App.Path & "ADDR.DAT"
  137.     Else
  138.     DataFile = App.Path & "\" & "ADDR.DAT"
  139.     End If
  140.  
  141.     ' Read in the names and addresses
  142.     Open DataFile For Input As #1
  143.     Do Until EOF(1)
  144.     Input #1, Surname
  145.     If EOF(1) Then Exit Do
  146.     ' .. in case there was a blank line
  147.     Input #1, Address
  148.     Addrs.Key = Surname
  149.     Addrs.Value = Address
  150.     Loop
  151.     Close #1
  152.  
  153.     ' Dump the arrays to the Debug window
  154.     Debug.Print
  155.     Debug.Print "Assoc ..."
  156.     Addrs.Key = ""
  157.     Do
  158.     Addrs.Key = Addrs.NextKey
  159.     If Addrs.Key = "" Then Exit Do
  160.     Debug.Print Addrs.Key, Addrs.Value
  161.     Loop
  162.  
  163.     ' Now dump them again using the Enumerate event
  164.     Debug.Print
  165.     Debug.Print "Assoc using Enumerate ..."
  166.     Addrs.Action = ASSOC_ENUMERATE
  167.  
  168. End Sub
  169.  
  170.